<%--
  Created by IntelliJ IDEA.
  User: WheelChen
  Date: 2017/5/5
  Time: 15:17
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<html>
<head>
    <title>修改密码</title>
    <link rel="stylesheet" href="/static/common/layui/css/layui.css">
</head>
<body>
<div style="margin: 15px;">
    <form class="layui-form" style="width: 50%">
        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
            <legend>修改密码</legend>
        </fieldset>
        <div class="layui-form-item">
            <label class="layui-form-label">当前密码</label>
            <div class="layui-input-block">
                <input type="password" name="password" autocomplete="off" class="layui-input" value=""
                       placeholder="请输入当前密码">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">新密码</label>
            <div class="layui-input-block">
                <input type="password" name="newPassword" autocomplete="off" class="layui-input" value=""
                       placeholder="请输入新密码">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">确认密码</label>
            <div class="layui-input-block">
                <input type="password" name="CheckNewPassword" autocomplete="off" class="layui-input" value=""
                       placeholder="请输入确认新密码">
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="submit" class="layui-btn" lay-filter="edit" lay-submit>立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>
<script src="/static/common/layui/layui.js"></script>
<script>
    layui.use(['form', 'jquery'], function () {
        var form = layui.form(),
            $ = layui.jquery;

        form.on('submit(edit)', function (data) {
            data.field.id = ${sessionScope.currentUser.getId()};
            console.log(data.field);
            $.ajax({
                url: '/user/modifyPwd'
                , type: 'post'
                , contentType: "application/json; charset=utf-8"
                , data: JSON.stringify(data.field)
                , dataType: 'json'
                , success: function (response) {
                    console.log(response);
                    layer.msg(response.message, {time: 1500, icon: 1}, function () {
                        location.reload();
                    });
                }
            });
            return false;
        });
    });
</script>
</body>
</html>
